#ifndef AUTO_FOCUS_H
#define AUTO_FOCUS_H

#include <QObject>
#include <opencv2/opencv.hpp>
#include <QQueue>
#include <QTimer>
#include <QMutex>

#include "focus_evaluation.h"
#include "focus_search.h"
#include "camera_lens_ctrl.h"

class AutoFocus : public QObject
{
	Q_OBJECT

public:
	AutoFocus(QObject *parent);
	~AutoFocus();

	void process();
	bool connectSerialPort(const QString& serialName);
	void start(int msec);
	void stop();

private:
	FocusEvaluation* focusEvaluation;
	FocusSearch* focusSearch;
	QQueue<double> focusValues;
	const int searchRange;
	CameraLensCtrl lensCtrl;
	bool isBorder;

	QTimer timer;
	bool isCaptured;
	QMutex mutex;
};

#endif

